/*
package com.summer.framework.common.controller;


import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.summer.framework.common.entity.response.ErrorResponse;
import com.summer.framework.common.exception.BaseException;
import com.summer.framework.common.exception.ParemeterException;
import com.summer.framework.common.util.RegexUtils;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

*/
/*
 *
 * @auther: 杨杰
 * @date: 2019/5/14 16:20
 * @description:  extends ResponseEntityExceptionHandler
 *//*

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler({BaseException.class})
    public ErrorResponse errorHandler(BaseException e) {
        log.info("BaseException 出现异常");
        e.printStackTrace();
        return new ErrorResponse(e.getStatus(), e.getMessage());
    }

    @ExceptionHandler(FeignException.class)
    public ErrorResponse feignExceptionHandler(HttpServletRequest request, HttpServletResponse response, FeignException ex) {
        log.info("FeignException 出现异常");
        ex.printStackTrace();
        response.setStatus(ex.status());
        Matcher jsonMatcher = RegexUtils.getMatcher(ex.getMessage(), "(\\{.*}$)", Pattern.DOTALL);
        if (jsonMatcher.find()) {
            JsonObject jsonObject = new JsonParser().parse(jsonMatcher.group(1)).getAsJsonObject();
            int status = jsonObject.get("status").getAsInt();
            String message = jsonObject.get("message").getAsString();
            return new ErrorResponse(status, message);
        } else {
            return new ErrorResponse(ex.status(), ex.getMessage());
        }
    }

    @ExceptionHandler(Exception.class)
    public ErrorResponse otherExceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception ex) {
        */
/*if(ex instanceof FlowException){
            log.info("=========限流===========");
        }*//*

        log.info("otherExceptionHandler 出现异常");
        ex.printStackTrace();
        return new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
    }


    @ExceptionHandler(HystrixRuntimeException.class)
    public ErrorResponse hystrixRuntimeException(Exception ex) {
        ex.printStackTrace();
        log.info("HystrixRuntimeException 出现异常:" + ex.getMessage());
        Throwable throwable = ex.getCause();
        log.info("throwable:" + throwable.getMessage());
        List<Throwable> list = ExceptionUtils.getThrowableList(throwable);
        for (Throwable item : list) {
            log.info("===item====" + item.getMessage());
        }
        return new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getCause().getMessage());
    }

    @Override
    protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers,
                                                             HttpStatus status, WebRequest request) {
        if (ex instanceof MethodArgumentNotValidException) {
            MethodArgumentNotValidException exception = (MethodArgumentNotValidException) ex;
            return new ResponseEntity<>(new BaseException(status.value(), exception.getBindingResult().getAllErrors().get(0).getDefaultMessage()), status);
        }
        if (ex instanceof MethodArgumentTypeMismatchException) {
            MethodArgumentTypeMismatchException exception = (MethodArgumentTypeMismatchException) ex;
            logger.error("参数转换失败，方法：" + exception.getParameter().getMethod().getName() + "，参数：" + exception.getName()
                    + ",信息：" + exception.getLocalizedMessage());
            return new ResponseEntity<>(new BaseException(status.value(), "参数转换失败"), status);
        }
        return new ResponseEntity<>(new BaseException(status.value(), "参数转换失败"), status);
    }

}

*/
